package com.wbk.lotterysystemlotteryservice.controller.auth;

import com.github.pagehelper.PageInfo;
import com.wbk.lotterysystemlotteryservice.commons.bo.DrawLotteryBO;
import com.wbk.lotterysystemlotteryservice.commons.bo.LotteryBO;
import com.wbk.lotterysystemlotteryservice.commons.dto.LotteryDTO;
import com.wbk.lotterysystemlotteryservice.commons.dto.LotteryRecordDTO;
import com.wbk.lotterysystemlotteryservice.commons.dto.LotteryWinDTO;
import com.wbk.lotterysystemlotteryservice.commons.dto.ResultDTO;
import com.wbk.lotterysystemlotteryservice.controller.auth.biz.LotteryBiz;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import result.Result;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

@Api
@RestController
@RequestMapping("/lottery/api/auth/lottery")
public class LotteryController {

    @Autowired
    LotteryBiz lotteryBiz;

    @ApiOperation(value = "创建抽奖活动接口", notes = "创建抽奖活动")
    @PostMapping("/createLottery")
    public Result<LotteryDTO> createLottery(@Valid @RequestBody LotteryBO lotteryBO) {
        return lotteryBiz.createLottery(lotteryBO);
    }

    @ApiOperation(value = "待审核的抽奖活动接口", notes = "待审核的抽奖活动")
    @GetMapping("/lotteryListWithoutAudit")
    public Result<PageInfo> lotteryListWithoutAudit(@ApiParam(value = "当前页") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                    @ApiParam(value = "每页的记录数") @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                    @ApiParam(value = "连续显示多少页") @RequestParam(value = "navigatePages", defaultValue = "5") Integer navigatePages) {
        return lotteryBiz.lotteryListWithoutAudit(pageNum, pageSize, navigatePages);
    }

    @ApiOperation(value = "修改抽奖活动内容接口", notes = "修改抽奖活动内容")
    @PostMapping("/updateLottery/{id}")
    public Result<LotteryDTO> updateLottery(@Valid @RequestBody LotteryBO lotteryBO, @ApiParam(value = "抽奖活动id") @PathVariable("id") Integer id) {
        return lotteryBiz.updateLottery(lotteryBO, id);
    }

    @ApiOperation(value = "查看商家的抽奖活动接口", notes = "查看商家的抽奖活动")
    @GetMapping("/lottery/{storeUserNo}")
    public Result<PageInfo> allLottery(@ApiParam(value = "当前页") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                       @ApiParam(value = "每页的记录数") @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                       @ApiParam(value = "连续显示多少页") @RequestParam(value = "navigatePages", defaultValue = "5") Integer navigatePages,
                                       @PathVariable("storeUserNo") Long storeUserNo) {
        return lotteryBiz.allLottery(pageNum, pageSize, navigatePages, storeUserNo);
    }

    @ApiOperation(value = "抽奖记录接口", notes = "抽奖记录")
    @GetMapping("/lotteryRecord/{id}")
    public Result<List<LotteryRecordDTO>> lotteryRecord(@ApiParam(value = "抽奖活动id") @PathVariable("id") Integer id) {
        return lotteryBiz.lotteryRecord(id);
    }

    @ApiOperation(value = "导出抽奖记录接口", notes = "导出抽奖记录")
    @GetMapping("/exportRecord/{id}")
    public Result<String> exportRecord(@ApiParam(value = "抽奖活动id") @PathVariable("id") Integer id, HttpServletResponse response) {
        return lotteryBiz.exportRecord(id, response);
    }

    @ApiOperation(value = "中奖记录接口", notes = "中奖记录")
    @GetMapping("/lotteryWin/{id}")
    public Result<List<LotteryWinDTO>> lotteryWin(@ApiParam(value = "抽奖活动id") @PathVariable("id") Integer id) {
        return lotteryBiz.lotteryWin(id);
    }

    @ApiOperation(value = "导出中奖记录接口", notes = "导出中奖记录")
    @GetMapping("/exportWin/{id}")
    public Result<String> exportWin(@ApiParam(value = "抽奖活动id") @PathVariable("id") Integer id, HttpServletResponse response) {
        return lotteryBiz.exportWin(id, response);
    }

    @ApiOperation(value = "查看用户参加过的抽奖活动接口", notes = "查看用户参加过的抽奖活动")
    @GetMapping("/hasJoin/{userNo}")
    public Result<PageInfo> hasJoin(@ApiParam(value = "当前页") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                    @ApiParam(value = "每页的记录数") @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                    @ApiParam(value = "连续显示多少页") @RequestParam(value = "navigatePages", defaultValue = "5") Integer navigatePages,
                                    @PathVariable("userNo") Long userNo) {
        return lotteryBiz.hasJoin(pageNum, pageSize, navigatePages, userNo);
    }

    @ApiOperation(value = "查看是否中奖接口",notes = "查看是否中奖")
    @GetMapping("/isWin/{id}")
    public Result<ResultDTO> isWin(@ApiParam(value = "抽奖活动id") @PathVariable("id") Integer id, @ApiParam(value = "抽奖活动id") @RequestParam(value = "userNo")Long userNo){
        return lotteryBiz.isWin(id,userNo);
    }

    @ApiOperation(value = "开奖接口",notes = "开奖")
    @PostMapping("/drawLottery")
    public Result drawLottery(@RequestBody DrawLotteryBO drawLotteryBO){
        return lotteryBiz.drawLottery(drawLotteryBO);
    }
}
